const CACHE_PREFIX = 'timetable_';
const DEFAULT_EXPIRE = 7 * 24 * 60 * 60 * 1000; // 7天

class Cache {
  static set(key, value, expire = DEFAULT_EXPIRE) {
    const data = {
      value,
      expire: Date.now() + expire
    };
    wx.setStorageSync(CACHE_PREFIX + key, data);
  }

  static get(key) {
    const data = wx.getStorageSync(CACHE_PREFIX + key);
    if (!data) return null;
    
    if (Date.now() > data.expire) {
      this.remove(key);
      return null;
    }
    
    return data.value;
  }

  static remove(key) {
    wx.removeStorageSync(CACHE_PREFIX + key);
  }

  static clear() {
    wx.clearStorageSync();
  }
}

export default Cache;